package com.wcy.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.User;
import com.wcy.entity.UserCollection;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.user.FeignUserCollectionService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class UserCollectionController {
    @Resource
    private FeignUserCollectionService feignUserCollectionService;

    @GetMapping("userCollection/page")
    public ResponseEntity<PageData<UserCollection>> getPage(@RequestParam(defaultValue = "1") int pageNum,
                                                            @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(UserCollection.class, Objects.requireNonNull(feignUserCollectionService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("userCollection/add", "userCollection/update", "userCollection/delete"), ColumnConstructor.create()));
    }

    @GetMapping("userCollection/list")
    public ResponseEntity<List<UserCollection>> getList() {
        return feignUserCollectionService.getList();
    }

    @PostMapping("userCollection/add")
    public ResponseEntity<Void> add(@RequestBody UserCollection userCollection) {
        return feignUserCollectionService.add(userCollection);
    }

    @PutMapping("userCollection/update")
    public ResponseEntity<Void> update(@RequestBody UserCollection userCollection) {
        return feignUserCollectionService.update(userCollection);
    }

    @DeleteMapping("userCollection/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Integer id) {
        return feignUserCollectionService.delete(id);
    }

    @GetMapping("userCollection/user/page")
    public ResponseEntity<PageData<UserCollection>> getUserCollectionPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                                      @RequestParam(name = "pageSize",defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(UserCollection.class, Objects.requireNonNull(feignUserCollectionService.getUserCollectionPage(pageNum, pageSize).getBody()),  new ApiDescriptor("", "", "userCollection/user/delete"), ColumnConstructor.create()).setAlias("取消收藏",""));
    }

    @GetMapping("userCollection/user/{id}")
    public ResponseEntity<Boolean> hasCollection(@PathVariable("id") Integer id) {
        return feignUserCollectionService.hasCollection(id);
    }

    @DeleteMapping("userCollection/user/delete/{id}")
    public ResponseEntity<Boolean> deleteCollection(@PathVariable Integer id) {
        return feignUserCollectionService.deleteCollection(id);
    }
    @PostMapping("userCollection/user/add/{id}")
    public ResponseEntity<Boolean> addCollection(@PathVariable Integer id) {
        return feignUserCollectionService.addCollection(id);
    }
}
